package com.bigModel.backend.service.impl.Device;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.bigModel.backend.advice.result.Result;
import com.bigModel.backend.mapper.DeviceMapper;
import com.bigModel.backend.pojo.DeviceInfo;
import com.bigModel.backend.service.Device.DeviceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeviceInfoServiceImpl implements DeviceInfoService {
    @Autowired
    private DeviceMapper deviceMapper;

    public DeviceInfo getDeviceInfoById(int id){
        QueryWrapper<DeviceInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_deleted",0);
        queryWrapper.eq("Id",id);
        DeviceInfo deviceinfo = deviceMapper.selectOne(queryWrapper);
        return deviceinfo;
    }
    public List<DeviceInfo> getDeivcelistAll() {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("is_deleted",0);
        List<DeviceInfo> list =deviceMapper.selectList(queryWrapper);
        return list;
    }

    public int deleteDeviceInfo(DeviceInfo deviceInfo) {
        UpdateWrapper<DeviceInfo> updateWrapper = new UpdateWrapper();
        updateWrapper.set("is_deleted",1);
        updateWrapper.eq("Id",deviceInfo.getId());
        try {
            int flag = deviceMapper.update(null, updateWrapper);
            return flag;
        }catch (Exception e){
            return 0;
        }
    }

    public int addDeviceInfo(DeviceInfo deviceInfo) {
        try {
            int flag = deviceMapper.insert(deviceInfo);
            return flag;
        }catch (Exception e){
            return 0;
        }
    }
}
